package com.singzi.testCase;

import org.junit.Test;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class IntegerTest {
    @Test
    public void test01(){
        int a = 5;
        Integer b = 5;
        Integer c = new Integer(5);
        Integer d = new Integer(5);
        System.out.println(a == b);
        System.out.println(c == d);
    }
    @Test
    public void compare(){
        Integer a = 1000;
        Integer b = 1000;
        int ab = 1000;
        Integer c = 10;
        Integer d = 10;
//        Integer e = new Integer(10);
        int e = 10;
        int cd = 10;

        System.out.println(a == b);
        System.out.println(a == ab);
        System.out.println(c == d);
        System.out.println(c == e);
        System.out.println(c == cd);
    }
}
class RandomizedSet {

    List<Integer> list;
    HashSet<Integer> set;

    public RandomizedSet() {
        set = new HashSet<>();
        list = new LinkedList<>();
    }

    public boolean insert(int val) {
        if(set.contains(val)) return false;
        else{
            list.add(val);
            set.add(val);
            return true;
        }

    }

    public boolean remove(int val) {
        if(!set.contains(val)) return false;
        else{
            set.remove(val);
            list.remove(new Integer(val));
            return true;
        }
    }

    public int getRandom() {

        Random rand = new Random();
        int a = rand.nextInt(set.size());
        return list.get(a);

    }

}
